package com.anysoft.utils;

/**
 * Created by wwq on 2017/3/28.
 * 银联支付的工具类
 */

public class ChinaPayUtils {

    private static final String TAG = "ChinaPayUtils";

    public static String getXml(String environment, String merchantId, String orderId, String orderTime,
                                String orderKey, String sign) {
        return "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
                "<CpPay application=\"LunchPay.Req\">"
                + "<env>" + environment + "</env>"
                + "<merchantId>" + merchantId + "</merchantId>"
                + "<merchantOrderId>" + orderId + "</merchantOrderId>"
                + "<merchantOrderTime>" + orderTime + "</merchantOrderTime>"
                + "<orderKey>" + orderKey + "</orderKey>"
                + "<sign>" + sign + "</sign>"
                + "</CpPay>";
    }

    /**
     * 打印银联认证结果码信息
     *
     * @param resultCode
     */
    public static void printChinapayResultCodeInfo(String resultCode) {
        String info;
        if ("0000".equals(resultCode)) {
            info = "成功";
        } else if ("9901".equals(resultCode)) {
            info = "网络连接超时";
        } else if ("9903".equals(resultCode)) {
            info = "报文解析错误";
        } else if ("9902".equals(resultCode)) {
            info = "中途退出";
        } else if ("9904".equals(resultCode)) {
            info = "配置文件验证失败";
        } else if ("9905".equals(resultCode)) {
            info = "调用参数不正确";
        } else if ("9906".equals(resultCode)) {
            info = "业务类型不支持";
        } else if ("2001".equals(resultCode) || "2002".equals(resultCode) || "2003".equals(resultCode)) {
            info = "通讯错误";
        } else if ("2004".equals(resultCode) || "2005".equals(resultCode)) {
            info = "订单错误";
        } else if ("2006".equals(resultCode)) {
            info = "系统异常";
        } else if ("2007".equals(resultCode)) {
            info = "通讯超时";
        } else if ("9999".equals(resultCode)) {
            info = "系统异常";
        } else {
            info = "未识别的的结果码";
        }
        MentorLogger.Log(TAG, "结果码：" + resultCode + ", " + info);
    }
}
